<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>AK JOB</title>
    <link rel="icon" type="image/x-icon" href="../../../layuiadmin/style/res/favicon.png"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card layui-padding-3">
        <div class="layui-form" lay-filter="applicationForm">
            <div class="layui-form-item">
                <label class="layui-form-label required">应用CODE</label>
                <div class="layui-input-block">
                    <input type="hidden" name="id" value="">
                    <input type="text" name="applicationName" lay-verify="required" placeholder="请输入应用CODE"
                           autocomplete="off"
                           lay-verType="tips"
                           class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">应用描述</label>
                <div class="layui-input-block">
                    <input type="hidden" name="id" value="">
                    <input type="text" name="applicationDes" lay-verify="required" placeholder="请输入应用描述"
                           autocomplete="off"
                           lay-verType="tips"
                           class="layui-input"/>
                </div>
            </div>
            <input type="button" class="layui-btn layui-hide" style="width: 100%" lay-submit
                   lay-filter="applicationFormSubmit"
                   id="applicationFormSubmit" value="保存">
        </div>
    </div>
</div>

<script src="../../../layuiadmin/layui/layui.js"></script>
<script src="../../../layuiadmin/lib/juicer-min.js"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'roles', 'table', 'setter', 'auth', 'AppHelper', 'application'], function () {
        var $ = layui.$
            , form = layui.form
            , roles = layui.roles
            , setter = layui.setter
            , table = layui.table
            , application = layui.application
            , AppHelper = layui.AppHelper
            , LayerPage = AppHelper.getLayerPage()
        ;
        //解析当前路由信息
        var router = layui.router();
        var action = router.search.action;
        var id = router.search.id;
        var namespaceId = router.search.namespaceId;

        var refreshParentTable = function () {
            parent.layui.table.reload("LAY-role-manage");
        }
        switch (action) {
            case "add":
                form.on("submit(applicationFormSubmit)", function (obj) {
                    var field = obj.field;
                    field.id = id
                    field.namespaceId = namespaceId;
                    //保存
                    var layerPageLoad = LayerPage.load();
                    application.methods.add(field, 1)
                        .done(function (res) {
                            if (res.code == "200") {
                                layerPageLoad.close();
                                parent.layer.msg("新增成功！", {icon: 1}, function () {
                                })
                                refreshParentTable();
                                LayerPage.close();
                            }
                        })
                        .fail(function () {
                            layerPageLoad.close();
                        });
                })
                break;
            case "edit":
                $.when(application.methods.info(id))
                    .done(function (adminReq) {
                        var adminInfo = adminReq.data;
                        //回显角色名称
                        form.val("applicationForm", {
                            "id": adminInfo.id
                            , "applicationName": adminInfo.applicationName
                            , "applicationDes": adminInfo.applicationDes
                        })
                        form.on("submit(applicationFormSubmit)", function (obj) {
                            var field = obj.field;
                            field.id = id
                            //保存
                            var layerPageLoad = LayerPage.load();
                            application.methods.update(field)
                                .done(function (res) {
                                    if (res.code == "200") {
                                        layerPageLoad.close();
                                        parent.layer.msg("修改成功！", {icon: 1}, function () {
                                        })
                                        refreshParentTable();
                                        LayerPage.close();
                                    }
                                })
                                .fail(function () {
                                    layerPageLoad.close();
                                });
                        })
                    })
                break;
        }


    });
</script>
</body>
</html>
